//
//  ST_PairsCenterDailyCell.swift
//  btvideo
//
//  Created by mac on 2020/7/24.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SDWebImage

class ST_PairsCenterDailyCell: UITableViewCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.selectionStyle = .none
        
        contentView.backgroundColor = UIColor.white
        
        self.addSubview(avatar_image_view)
        avatar_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(44)
            make.top.equalToSuperview().offset(18)
            make.left.equalToSuperview().offset(15)
        }
        
        self.addSubview(icon_supplement_image_view)
        icon_supplement_image_view.snp.makeConstraints { (make) in
            make.center.equalTo(avatar_image_view)
            make.width.height.equalTo(60)
        }
        
        self.addSubview(username_label)
        username_label.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(69)
            make.top.equalToSuperview().offset(20)
            make.height.equalTo(22)
        }
        self.addSubview(time_label)
        time_label.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(69)
            make.top.equalTo(username_label.snp.bottom).offset(1)
            make.height.equalTo(17)
        }
        
        
        self.addSubview(signView)
        signView.snp.makeConstraints { (make) in
            make.height.equalTo(18)
            make.width.equalTo(70)
            make.centerY.equalTo(username_label)
            make.left.equalTo(username_label.snp.right).offset(4)
        }
        
        self.addSubview(imageContainer)
        imageContainer.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(70)
            make.left.equalToSuperview().offset(69)
            make.size.equalTo(CGSize.zero)
        }
        
        self.addSubview(dailySignView)
        dailySignView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(30)
            make.left.equalToSuperview().offset(69)
            make.height.equalTo(ST_DailyMomentSignView.height)
        }
        
        self.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(69)
            make.right.equalToSuperview().offset(-15)
            make.top.equalToSuperview().offset(30)
            make.size.equalTo(CGSize.zero)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
    //    MARK: - Properties
    
    fileprivate lazy var avatar_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = .scaleAspectFill
        control.cornerRadius = 44/2.0
        return control
    }()
    
    fileprivate lazy var icon_supplement_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        return control
    }()
    
    fileprivate lazy var signView:ST_UserSignView = {
        let control = ST_UserSignView()
        return control
    }()
    
    fileprivate lazy var username_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = UIColor.init(hexString: "#333333")
        control.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)
        return control
    }()
    
    fileprivate lazy var time_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = UIColor.init(hexString: "#ACB4C0")
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        return control
    }()
    
    
    fileprivate lazy var imageContainer:ST_DailyMomentImageContainer = {
        let control = ST_DailyMomentImageContainer()
        return control
    }()
    
    fileprivate lazy var dailySignView:ST_DailyMomentSignView = {
        let control = ST_DailyMomentSignView()
        control.addTarget(self, action: #selector(pushSomeDailyHandle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel()
        control.numberOfLines = 0
        
        return control
    }()
    
    weak var model:ST_PairsOwnDailySetsModel?{
        didSet{
            
            guard let m = model?.data else{
                return
            }
            
            avatar_image_view.sd_setImage(with: m.avatar.compress_image().url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image(), options: SDWebImageOptions(), context: nil)
            
            icon_supplement_image_view.pin_setImage(from: AVATAR_SUPPLEMENT(guardTime: m.guardTime, guardContent: m.guardContent)?.url)
            
            
            username_label.text = m.nickname
            
            time_label.text = m.createStr
            
            signView.bind_data(isVip: m.isVip, detectedFace: m.detectedFace)
            
            imageContainer.snp.updateConstraints { (make) in
                make.size.equalTo(m.mediaSize)
            }
            
            imageContainer.imagesArray = m.contentImages
            
            dailySignView.bind(text: m.name, url: m.image)
            
            dailySignView.snp.updateConstraints { (make) in
                make.top.equalToSuperview().offset(m.signTopConstraint)
            }
            
            content_label.attributedText = m.contetnAttriStr
            
            content_label.lineBreakMode = .byTruncatingTail
            
            content_label.snp.updateConstraints { (make) in
                make.top.equalToSuperview().offset(m.contentTopConstraint)
                
                make.size.equalTo(m.contentSize)
            }
            
        }
    }
    
}

extension ST_PairsCenterDailyCell{
    
    @objc fileprivate func pushSomeDailyHandle(){
        
        
        let vc = ST_SomeOneDailyViewController()
        vc.dailyModel = self.model?.data?.conver_to_daily_base_model()
        self.parentViewController?.navigationController?.pushViewController(vc)
    }
}
